<?php
/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-09 0:20
 */

namespace App\Listener\WebSocket\Message;

use App\Event\Talk\ChatEvent;
use App\Event\Talk\StartChatEvent;
use App\Service\WebSocket\Message\ChatService;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;


/**
 * @Listener()
 */
class ChatListener implements ListenerInterface
{

    public function listen(): array
    {
        return [
            ChatEvent::class,
            StartChatEvent::class
        ];
    }

    public function process(object $event)
    {
        if ($event instanceof ChatEvent) {
            /** @var ChatEvent $ChatEvent */
//            $ChatEvent = $event;
            //记录消息
            App(ChatService::class)->handle($event);
        }

        if ($event instanceof StartChatEvent){
            App(ChatService::class)->startChat( $event);
        }

        //插入数据

        // TODO: Implement process() method.
    }
}